// 未完成
#include <bits/stdc++.h>
using namespace std;

struct Bag {
  int outer_diameter;
  int inner_diameter;
};

bool compareBags(const Bag &a, const Bag &b) {
  if (a.outer_diameter == b.outer_diameter) {
    return a.inner_diameter < b.inner_diameter;
  }
  return a.outer_diameter < b.outer_diameter;
}

int maxNestedBags(vector<Bag> &bags) {
  int n = bags.size();
  sort(bags.begin(), bags.end(), compareBags);

  vector<int> dp(n, 1);
  int max_bags = 1;

  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < i; ++j) {
      if (bags[j].outer_diameter < bags[i].inner_diameter) {
        dp[i] = max(dp[i], dp[j] + 1);
      }
    }
    max_bags = max(max_bags, dp[i]);
  }

  return max_bags;
}

int main() {
  int n;
  cin >> n;
  vector<Bag> bags(n);
  for (int i = 0; i < n; ++i) {
    cin >> bags[i].outer_diameter >> bags[i].inner_diameter;
  }

  cout << maxNestedBags(bags) << endl;
  return 0;
}
